from os import lseek
from huobi.client.generic import GenericClient
from huobi.utils import *
import time
import os
import math

generic_client = GenericClient()
ts = generic_client.get_exchange_timestamp()
print("before sync-----")
print("serverTime",ts/1000)
print("localTime",time.time())

sync_time = math.ceil(ts/1000)
sleep_diff = sync_time - ts/1000
t = time.localtime(sync_time)
time.sleep(sleep_diff)
time_str = time.strftime("%m/%d/%Y %H:%M:%S", time.localtime()) # 获取当前时间
cmd = f'date -s "{time_str}";hwclock -w'  # 设置时间并写入bios
os.system("date -s "+cmd)

ts = generic_client.get_exchange_timestamp()
print("after sync-----")
print("serverTime",ts/1000)
print("localTime",time.time())
